/*
 *  $Id: UniqueAngelIllusion.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Light.Creatures {
    public class UniqueAngelIllusion: CreatureCard {
        public UniqueAngelIllusion(): base("001_l_c_u_angel_illusion") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Light;
            Value = 100;
            MaxCount = 1;
            SetRace<Races.Angel>();
            Damage = 5;
            Health = 10;
            AddManaCost(ElementType.Light, 10);
            AddManaCost(ElementType.Earth, 10);
        }

        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.Hero>();
            affects.Add<Affects.Antimagic>();
            affects.Add<IllusionHypnoise>();
        }

        public override void SetAbilities(ICollector<AbilityCard> abilities) {
            abilities.Add<Abilities.EternityIllusion>();
            abilities.Add<Abilities.GodlikeIllusion>();
            abilities.Add<Abilities.WarIllusion>();
        }

        private class IllusionHypnoise: Affect {
            private Creature _killer;

            public IllusionHypnoise() {
                _killer = null;
            }

            public override string Id {
                get { return AffectManager.GetCardId<UniqueAngelIllusion>(null); }
            }

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnAfterDamage += DoDamage;
                LocalSummary.OnDeath += DoDeath;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnAfterDamage -= DoDamage;
                LocalSummary.OnDeath -= DoDeath;
            }

            private void DoDamage(AbstractObject target, DamageInfo damage) {
                if (!target.IsDeath) return;
                MeleeDamageInfo.TryGetAttacker(damage, out _killer);
            }

            private void DoDeath(AbstractObject obj) {
                if (_killer != null)
                    _killer.MoveToPlayer(obj.Owner);
            }
        }
    }
}
